package session1.examples.chap2;

public class Eg1 implements Runnable{
	public static void main(String[] args) {
		System.out.println("Main started");
		Eg1[] myRunnables={new Eg1("Thread A"),
				new Eg1("Thread B")};
		Thread[] threads=new Thread[myRunnables.length];
		int i=0;
		for(Eg1 eg1:myRunnables)
			threads[i++]=new Thread(eg1);
		for(Thread thread:threads)
			thread.start();
		System.out.println("Main ended");
	}
	String threadName;
	public Eg1(String threadName) {
		this.threadName = threadName;
	}
	@Override
	public void run() {
		for (int i=0;i<3;i++){
			System.out.println("Running Thread: "+threadName);
			try {Thread.sleep((int)(Math.random())*1000);}
			catch (InterruptedException interruptedException){
				System.err.println(interruptedException);
			}
		}
	}
}
